package com.ztz.mynewdemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ztz.mynewdemo.R;
import com.ztz.mynewdemo.activity.ImagePagerActivity;
import com.ztz.mynewdemo.bean.UpdateAmuResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wqewqe on 2017/5/19.
 */

public class UpdateAmuAdapter extends RecyclerView.Adapter<UpdateAmuAdapter.ViewHolder> {
    Context context;
    List<UpdateAmuResponse.ResultBean.DataBean> dataBeanList;

    public UpdateAmuAdapter(Context context, List<UpdateAmuResponse.ResultBean.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_amusing,parent,false);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvAmuCon.setText(dataBeanList.get(position).getContent());
        Glide.with(context).load(dataBeanList.get(position).getUrl()).into(holder.imgAmu);
        holder.upAmu.setText(dataBeanList.get(position).getUpdatetime());
        final ArrayList<String> urls = new ArrayList<>();
        urls.add(dataBeanList.get(position).getUrl());
        holder.imgAmu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ImagePagerActivity.class);
                intent.putExtra(ImagePagerActivity.IMAGE_INDEX, position);
                intent.putStringArrayListExtra(ImagePagerActivity.IMAGE_URL, urls);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        CardView cardView;
        TextView tvAmuCon;
        ImageView imgAmu;
        TextView upAmu;
        public ViewHolder(View view) {
            super(view);
            cardView=(CardView)view;
            tvAmuCon=(TextView)view.findViewById(R.id.tv_amuContent);
            imgAmu=(ImageView)view.findViewById(R.id.img_amu);
            upAmu=(TextView)view.findViewById(R.id.amu_upTime);
        }
    }
}
